package com.videoaggre.zcl.ui.activity.agefans

import androidx.recyclerview.widget.DividerItemDecoration
import com.videoaggre.zcl.R
import com.videoaggre.zcl.bean.AgefansItem
import com.videoaggre.zcl.common.getString
import com.videoaggre.zcl.common.showEmptyCallback
import com.videoaggre.zcl.helper.newInstance
import com.videoaggre.zcl.parse.BaseParse
import com.videoaggre.zcl.parse.impl.AgefansParse
import com.videoaggre.zcl.ui.adapter.AgefansSearchItemAdapter
import com.videoaggre.zcl.ui.fragment.parseHtml
import com.videoaggre.zcl.utils.Utils
import kotlinx.android.synthetic.main.agefans_activity_search.*
import kotlinx.android.synthetic.main.activity_base_refresh.*

class AgefansSearchActivity : AgefansBaseRefreshActivity<AgefansItem>(R.layout.agefans_activity_search) {
    private val mAgefansSearchItemAdapter: AgefansSearchItemAdapter by newInstance()
    override fun initView() {
        svSearch.hint = R.string.agefans_text_search.getString()
        svSearch.clearListener = ::onReload
        mBaseRecyclerAdapter = mAgefansSearchItemAdapter
        recyclerView.addItemDecoration(DividerItemDecoration(this, DividerItemDecoration.VERTICAL))
        super.initView()
    }

    override fun initData() {
        mLoadService.showEmptyCallback()
    }

    override fun onReload() {
        Utils.hideSoftInput(this)
        if (svSearch.text.isNotEmpty()) {
            parseHtml(BaseParse(this, this, AgefansParse.createSearchLink(svSearch.text, mAgefansPage.currentPage), loadService = mLoadService, refreshLayout = refreshLayout) {
                AgefansParse.parseSearch(it) {
                    handResult(it)
                }
            })
        }
    }
}